-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inject balances from json into chainspec #3114
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure we need to include this in the software in JSON? It'll make every node build ~12M larger. Compressing it with zstd will reduce the size to ~4M for example.
use sp_runtime::traits::Zero; | ||
|
||
pub fn get_genesis_allocations() -> Vec<(AccountId, Balance)> { | ||
let file_content = include_str!("genesis_allocations.json"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We typically store such things in a constant at the top of the file, not in local variable, see the chain spec example. Also I'd make this function take contents as an argument with constant that contains JSON being in the chain spec file.
let allocations: Value = serde_json::from_str(file_content) | ||
.expect("Failed to parse genesis allocations JSON"); | ||
|
||
allocations.as_array() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these types implement Serde. You can just define the shape and then decode the whole thing without manually iterating over it, for balances you can use NonZeroU128
to automatically check the invariant.
That is unless you want to have nice error messages here (that should never really happen anyway).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure we need to include this in the software in JSON? It'll make every node build ~12M larger. Compressing it with zstd will reduce the size to ~4M for example.
Can we reduce the file size using arrays rather than key/value maps?
That would look like:
[
[
"stBJ4naCdaku9nTXrcQ8m8XQSa4arro9pSdW3eaj6skgW9Nwg",
"1000000000000000000000"
],
[
"st9idRv3z62dVwfmjLaNiq1FVb2B2j3giib7ns4Vni1wZ9ePj",
"1106022470000000000000000"
],
...
]
It also seems like all the amounts end in 15 zeroes, so maybe we could do that multiplication in code?
If this large file isn't final, then compressing it will also add 4 MB to the Git repository every time it changes. If we are going to compress it, there's no need for so much white space, so we could run it through a script that removes all white space before compressing it.
If it's uncompressed, it will add 12 MB to Git, but the diffs will be smaller.
Is there a way to just store the file hash in the node/git, and download the latest file when the node starts? Or distribute the file with the node build?
This is supposed to be a part of the chain spec, so it will be awkward to distribute it separately and I'd really prefer to not have it depend on the download from somewhere. At the same time this large blob will end up copied into the actual mainnet chain spec, which in turn means our chain spec will be permanently huge. So we will remove the file shortly afterwards, but the ballooned chain spec will stay with us basically forever. Repo size is a smaller concern for me, this is a really important information to have persisted in history. But I agree that we should wait for the very final version rather than adding multiple revisions of this large file. |
I have added the file, even if not final, to test the "real deal" and wanted us to align on a preferred way to handle such case, because that is the size of the file we will be dealing with on mainnet. If we decide on format/workflow here, in the next PR I can just swap the allocations file for the final one. |
Perhaps adding the file to a separate repro and using it as |
It really doesn't if you need to clone submodule for code to compile anyway 🙂 |
In the final file it will be closer to 8 trailing zeroes, but I would rather not introduce into the code assumptions about precision of underlying file. |
I think changing to arrays and removing spaces will help keep the size of the file down. (I don’t want to remove new lines, because that makes diffs much harder to see.) Is there anything we need to test on testnet that would be missed by having a small chain spec file? |
@@ -86,7 +87,7 @@ pub fn gemini_3h_compiled() -> Result<GenericChainSpec, String> { | |||
AccountId::from_ss58check("5DNwQTHfARgKoa2NdiUM51ZUow7ve5xG9S2yYdSbVQcnYxBA") | |||
.expect("Wrong root account address"); | |||
|
|||
let balances = vec![(sudo_account.clone(), 1_000 * SSC)]; | |||
let balances=get_genesis_allocations(GENESIS_ALLOCATIONS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should make rustfmt happier
let balances=get_genesis_allocations(GENESIS_ALLOCATIONS); | |
let balances = get_genesis_allocations(GENESIS_ALLOCATIONS); |
In the next iteration, the file will change basically on every line since the precision will be higher and post-merge there should not ever be a diff to genesis balances. |
Sure, we can always run it through |
It is required to keep the chain spec file manageable with thousands of balances. The JSON file is NOT final as it only contains farmer rewards and no other allocations (team, fdn, etc.).
Tested on devnet on Oct 9.
Code contributor checklist: